﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace WcfHost {
    class WcfWorkerConfigurationSection : ConfigurationSection {

            /// <summary>
            /// Gets all worker threads specified in the configuration file.
            /// </summary>
            /// <value>The services.</value>
            [ConfigurationProperty("workers", IsDefaultCollection = false)]
            [ConfigurationCollection(typeof(WorkerElementCollection))]           
            public WorkerElementCollection Workers {
                get {
                    WorkerElementCollection workerColl = (WorkerElementCollection)base["workers"];
                    return workerColl;
                }
            }
        }

        /// <summary>
        /// Represents a list of worker elements in a configuration file.
        /// </summary>
        public class WorkerElementCollection : ConfigurationElementCollection {

            protected override ConfigurationElement CreateNewElement() {
                return new WorkerConfigurationElement();
            }

            protected override Object GetElementKey(ConfigurationElement element) {
                return ((WorkerConfigurationElement)element).Name;
            }

        }

        /// <summary>
        /// Represents a single config element
        /// </summary>
        public class WorkerConfigurationElement : ConfigurationElement {

            /// <summary>
            /// Gets or sets the name.
            /// </summary>
            /// <value>The name.</value>
            [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
            public string Name {
                get {
                    return (string)this["name"];
                }
                set {
                    this["name"] = value;
                }
            }

            /// <summary>
            /// Gets or sets the name.
            /// </summary>
            /// <value>The name.</value>
            [ConfigurationProperty("interval", IsRequired = true, IsKey = false)]
            public int Interval {
                get {
                    return (int)this["interval"];
                }
                set {
                    this["interval"] = value;
                }
            }


            /// <summary>
            /// Gets or sets the worker type.
            /// </summary>
            /// <value>The type.</value>
            [ConfigurationProperty("workerType", IsRequired = true)]
            public string WorkerType {
                get {
                    return (string)this["workerType"];
                }
                set {
                    this["workerType"] = value;
                }
            }        

        }
    }

